package org.nbile.component;

import org.stellar.sdk.KeyPair;
import org.stellar.sdk.Server;
import org.stellar.sdk.requests.RequestBuilder;
import org.stellar.sdk.responses.Page;
import org.stellar.sdk.responses.effects.EffectResponse;

/**
 * Document Start 
 * 事件组件
 * Document End 
 * Author: songwenpeng@le.com
 * Time: 2016年11月7日 下午2:12:44
 */
public class EffectComponent {

	/**
	 * Document Start 
	 * 获取指定账户的事件
	 * Document End 
	 * Author: songwenpeng@le.com
	 * Time: 2016年11月7日 下午3:05:06
	 * @param accountID
	 * @return
	 */
	public Page<EffectResponse> effectsForAccount(Server server, String accountID) {
		//创建源 目标 账户对象
		KeyPair account = KeyPair.fromAccountId(accountID);
		try {
			// First, check to make sure that the destination account exists.
			// You could skip this, but if the account does not exist, you will be charged
			// the transaction fee when the transaction fails.
			// It will throw HttpResponseException if account does not exist or there was another error.
			server.accounts().account(account);
			Page<EffectResponse> response = server.effects().forAccount(account).limit(200).order(RequestBuilder.Order.DESC).execute();
			return response;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * Document Start 
	 * 处理Effect
	 * Document End 
	 * Author: songwenpeng@le.com
	 * Time: 2016年11月7日 下午3:18:37
	 * @param events
	 */

	public void handleEffect(Page<EffectResponse> effects) {
//		ArrayList<EffectResponse> effectResponse = effects.getRecords();

	}

}
